<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\web\Response;

class SiteController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ]
        ];
    }

    /**
     * @return string
     */
    public function actionIndex()
    {
        return $this->render('index', [
            'code' => 0,
            'msg' => 'welcome lusheep.'
        ]);
    }

    /**
     * @return string[]
     */
    public function actionDocker(): array
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return [
            'docker_start' => "docker run -d -p 80:80 -v /opt/web/lusheep.top/:/opt/website/:rw -v /opt/web/lusheep.top/redu.conf:/etc/nginx/conf.d/cloud.conf:rw -v /opt/web/lusheep.top/nginx.conf:/etc/nginx/nginx.conf:rw --name lusheep-web yiisoftware/yii2-php:7.4-fpm-nginx"
        ];

    }

    /**
     * 微信公众号校验token
     */
    public function actionCheckToken()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        $signature = $_GET['signature'];
        $timestamp = $_GET['timestamp'];
        $echostr = $_GET['echostr'];
        $nonce = $_GET['nonce'];
        $token = 'lusheep821';
        $arr = [$token, $timestamp, $nonce];
        sort($arr, SORT_STRING);
        $shaString = implode($arr);
        $sign = sha1($shaString);
        if ($sign == $signature) {
            echo $echostr;
            exit;
        } else {
            echo '失败';
            exit;
        }
    }

}
